// evaluate.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    sn:'',
    service_score_count: [0,0,0,0,0],
    service_score: 0,
    product_score_count: [0, 0, 0, 0, 0],
    product_score: 0,
    level: 2,
    order_id: '',
    comment: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      sn: options.sn,
      order_id: options.options
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },


  /**
   * 提交评价
   */
  submitEvaluate: function () {
    var that = this

    getApp().http.request({
      url: '/api/v1/merchant/do_rate?sn=' + that.data.sn 
      + '&level=' + that.data.level 
      + '&comment=' + that.data.comment 
      + '&service_score=' + that.data.service_score 
      + '&product_score=' + that.data.product_score, 
      data: {
      },
      success: function (res) {
        console.log('success');
        console.log(res.data.data)
        if (res.data.code == '200') {
            wx.showToast({
              title: '评价成功',
              duration:2000,
              complete:function(){
                wx.navigateBack({
                  delta: 1
                })
              }
            })
        }else{
          wx.showToast({
            title: res.data.msg,
              duration:2000
          })
        }
      },
      fail: function () {
        console.log('fail');
      }
    })
  },
  
  serviceScoreEvent: function (event) {
    console.log(event.currentTarget.dataset.index)
    this.setData({
      service_score: event.currentTarget.dataset.index+1
    })
  },
  productScoreEvent: function (event) {
    console.log(event.currentTarget.dataset.index)
    this.setData({
      product_score: event.currentTarget.dataset.index + 1
    })
  },
  levelEvent: function (event) {
    this.setData({
      level: event.currentTarget.dataset.index
    })
  },
  bindTextAreaBlur: function (e) {
    this.setData({
      comment: e.detail.value
    })
  },
})